package com.itheima.service.impl;

import com.itheima.domain.Member;
import com.itheima.mapper.MemberMapper;
import com.itheima.service.MemberService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: hsp
 * @Date: 2022/11/17-11-17-21:41
 * @Description: com.itheima.service.impl.impl
 * @version: 1.0.0
 */
@Service
public class MemberServiceImpl implements MemberService {

    @Resource
    private MemberMapper memberMapper;

    /**
     * 查询会员列表
     * @return
     */
    @Override
    public List<Member> findAll() {
        return memberMapper.selectList(null);
    }

    /**
     * 添加会员
     * @param member
     */
    @Override
    public void save(Member member) {
        memberMapper.insert(member);
    }

    /**
     * 修改会员
     * @param member
     */
    @Override
    public void update(Member member) {
        memberMapper.updateById(member);
    }

    /**
     * 根据id查询会员列表(回显数据)
     * @param id
     * @return
     */
    @Override
    public Member findById(Integer id) {
        return memberMapper.selectById(id);
    }

    /**
     * 根据id删除单个会员
     * @param id
     */
    @Override
    public void deleteById(Integer id) {
        memberMapper.deleteById(id);
    }

    /**
     * 根据id批量删除会员
     * @param ids
     */
    @Transactional
    @Override
    public void deleteByIds(Integer[] ids) {
        if (ids != null && ids.length > 0){
            for (Integer id : ids) {
                memberMapper.deleteById(id);
            }
        }
    }


}
